package com.hzncc.flowable_diboot.controller;


import com.hzncc.flowable_diboot.dto.ScreenDto;
import com.hzncc.flowable_diboot.rabbitmq.service.MqttGateway;
import com.hzncc.flowable_diboot.service.impl.ScreenDataServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/api/top")
public class TopController
{
    @Autowired
    private MqttGateway mqttGateway;

    /**
     * 发送MQTT消息
     *
     * @param message 消息内容
     * @return 返回
     */
    @PostMapping(value = "/mqtt", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<String> sendMqtt(@RequestParam(value = "msg") String message) {
        System.out.println("================生产MQTT消息================" + message);
        mqttGateway.sendToMqtt(message);
        return new ResponseEntity<>("OK", HttpStatus.OK);
    }


    /**
     * 发送MQTT消息
     * @param key  表示要发给那个频道，例（admin/123/admin、admin/sss/admin、test、subTopic.............）
     * @param message 消息内容
     * @return 返回
     */
    @PostMapping(value = "/mqtt2", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<String> sendMqtt2(@RequestParam(value = "key")String key,@RequestParam(value = "msg") String message) {
        System.out.println("================生产MQTT消息================" + message);
        mqttGateway.sendToMqtt(key, message,true);
        return new ResponseEntity<>("OK", HttpStatus.OK);
    }

    @Autowired
    ScreenDataServiceImpl screenDataService;
    @GetMapping(value = "/test")
    public Object test(){
        ScreenDto screenDto = new ScreenDto();
        screenDto.setTenantId("1791742964004937730");
        Object bj = screenDataService.customerDistribution(screenDto);
        return bj;
    }
}